package com.android.nextBus.Activities;

import com.android.nextBus.DB.SQLiteOperationsWrapper;
import com.android.nextBus.Data.CredentialsItem;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;


/**
 * This activity is for logging into change one's credentials
 */
public class AccountLoginActivity extends Activity {
	
	private EditText passwordEntry;
	
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		setContentView(R.layout.login_screen);
		passwordEntry = (EditText)findViewById(R.id.passwordEntryFieldLoginScreen);
		
	}
	
	public void fromLoginScreenToMainContentOnClick(View v){
		
		//get instance of the database
		SQLiteOperationsWrapper db = new SQLiteOperationsWrapper(this);
		
		//open the database
		db.open();

		//Get the current credentials from the Database
		CredentialsItem ci = db.getCredentials();
		
		//now close the data base
		db.close();
		
		//check for the correct password
		if(ci.getPassword().equals(passwordEntry.getText().toString())){
			
			//continue to account creation screen 
			Intent intent = new Intent(getApplicationContext(), AccountCreationActivity.class);
			startActivity(intent);
			finish();
		}else{
			passwordEntry.setError("Incorrect password, Please try again");
		}
		
		
	}
	

}
